# author: zrs
# version:3.1
# date: 2022-12-05
# desc: version for cgft

import sys
import warnings

import requests


'''
原图   rawimage
切图fit图   cutimagefit
切图png图   cutimagepng
图像参数     imageparam
证认图       findchart
光变曲线     lightcurve
光变变化参数  lightcurveparam
其他   other

data_source   数据来源的区分，现在是有两条链路的数据会过来
不清楚的可以不用填,必选项只有3个,file-type, trigger-name, file_path

2.1 版本更新
1、这个版本去掉了version,暂不对版本进行管理
2、instrument 为字符串，可以直接填望远镜名称
'''



warnings.filterwarnings('ignore')

class SendFile:
    def __init__(self):
        self.file_type = None
        self.trigger_name = None
        self.req_id = None
        self.cc_id = None
        self.instrument = None
        self.obs_time = None
        self.observer = None
        self.uploader = None
        self.note = None
        self.data_source = None
        self.file_path = None
        self.filter = None


    def send_file(self):
        # url = 'http://localhost:8080/dataManagement_war_exploded/uploadfile'
        url = 'http://192.168.199.130:10088/dataupload/uploadfile'
        data = {'file-type':self.file_type,  #文件类型，内容为字符串
                'trigger-name':self.trigger_name,  #内容为字符串
                'req-id':self.req_id, #内容为 int
                'cc-id': self.cc_id, #内容为 int
                'instrument' : self.instrument, #内容为字符串
                'obs-time' : self.obs_time, #内容为时间，日期和时间中间有T
                'observer' : self.observer, #内容为字符串 
                'uploader' : self.uploader, #内容为字符串
                'note' : self.note, #内容为字符串
                'data_source' : self.data_source, #内容为字符串
                'filter' : self.filter} #内容为字符串

        files = {'image': open(self.file_path, 'rb')}
        res = requests.post(url, data=data, files=files)
        # res = requests.post(url, files=files)
        print(res.text)
        print(res.content)


if __name__ == '__main__':
    #send = SendFile()
    #send.file_type = 'rawimage'
    #send.trigger_name = '663645963'
    #send.data_source = 'test'
    #send.obs_time = '2022-02-22T22:22:22'
    #send.file_path = '/Users/gwac/john/data/flat/flat_I_220103_00001.fit'
    #send.send_file()
    
    send = SendFile()
    send.file_type = str(sys.argv[1])
    send.trigger_name = str(sys.argv[2])
    send.req_id = int(sys.argv[3])
    send.cc_id = int(sys.argv[4])
    send.instrument = str(sys.argv[5])
    send.obs_time = str(sys.argv[6])
    send.observer = str(sys.argv[7])
    send.uploader = str(sys.argv[8])
    send.note = str(sys.argv[9])
    send.data_source = str(sys.argv[10])
    send.file_path = str(sys.argv[11])
    send.filter = str(sys.argv[12])
    send.send_file()
    #   cutimagepng  Test001GRB  001 002 CGFT  2022-02-22T22:22:22  cgft   pipeline  01 test   fitsname
